import UIKit

extension UIViewController {
    static func themeableSetups() {
        ThemeTool.objc_swizzleSelector1(
            #selector(viewDidLoad),
            inClass1: Self.self,
            withSelector2: #selector(self_viewDidLoad),
            inClass2: Self.self
        )
    }

    /// when self is `awakeFromNib` or `themeStyleDidChange`,
    /// then update setting the `theme configured semantic color`
    @objc private func self_viewDidLoad() {
        self_viewDidLoad()
        
        guard let _ = self as? DemoThemeAdaptable else {
            return
        }
        
        (self as? DemoThemeAdaptable)?.updateThemeStyleIfNeeded()
        
        NotificationCenter.default.addObserver(self, selector: #selector(themeStyleDidChange), name: .DemoThemeStyleDidChange, object: nil)
    }
    
    @objc private func themeStyleDidChange() {
        (self as? DemoThemeAdaptable)?.updateThemeStyleIfNeeded()
    }
}
